const express = require('express')
const router = express.Router()
const User = require('../../modules/user')
const passport = require('passport')
//修改密码
router.post('/change', passport.authenticate('jwt', { session: false }), (req, res) => {
  User.findById(req.query.id).then(res2=>{
    console.log(res2)
    if(res2.password===req.body.old){
      User.updateOne({_id:req.query.id},{password:req.body.new}).then(res3=>{
        res.status(200).json({
          result:'0',
          message:'修改密码成功'
        })
      })
    }else{
      res.status(200).json({
        result:'1',
        message:'密码错误'
      })
    }
  }).catch(err=>{
    res.status(500).json({
      result:'2',
      message:'服务器错误'
    })
  })
})

router.get("/", function (req, res) {

  res.redirect("/views/index.html")
})

module.exports = router